//
//  UIButton+clickBtn.m
//  clickBtn
//
//  Created by chenleping on 2018/9/3.
//  Copyright © 2018年 DSY. All rights reserved.
//

#import "UIButton+clickBtn.h"

#import <objc/runtime.h>
#import <AFNetworking.h>
@implementation UIButton (clickBtn)

+ (void)load{

    [super load];

    Method oldObjectAtIndex =class_getInstanceMethod([UIButton class],@selector(sendAction:to:forEvent:));
    Method newObjectAtIndex =class_getInstanceMethod([UIButton class], @selector(custom_sendAction:to:forEvent:));
    method_exchangeImplementations(oldObjectAtIndex, newObjectAtIndex);

}

- (void)sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event{
    [super sendAction:action to:target forEvent:event];
}

- (void)custom_sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event{
    // 有问题  有时只打印出“走了...”
    NSLog(@"%@  走了...", target);
    AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager manager];
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        if (status == AFNetworkReachabilityStatusNotReachable || status == AFNetworkReachabilityStatusUnknown) {
            NSLog(@"无网络连接....");
            return ;
        }else{  // 如果有网络继续走系统方法
            [self custom_sendAction:action to:target forEvent:event];
        }
    }];
    [manager startMonitoring];

}



@end
